#ifndef BUYWINDOW_H
#define BUYWINDOW_H

#include <QWidget>
#include "databasefunction.h"
#include "traininfo.h"
namespace Ui {
class BuyWindow;
}

class BuyWindow : public QWidget
{
    Q_OBJECT

public:
    explicit BuyWindow(QWidget *parent = nullptr);
    ~BuyWindow();
    void clearAll();
private slots:
    void receiveTrainNum(QString,QString);
    void on_returnBtn_clicked();

    void on_startComboBox_currentTextChanged(const QString &arg1);

    void on_endComboBox_currentTextChanged(const QString &arg1);

    void on_buyBtn_clicked();

    void on_collectBtn_clicked();

private:
    Ui::BuyWindow *ui;
    DatabaseFunction *db;
    TrainInfo trainList;
    QString username;

    void initTrainList(QSqlQuery);
    void initWindowItems();
    void updateWindowItems();
    void updateLeftTickets(QString,QString,QString);
    int computeLeftTickets(int,int);
    int computePrice(int,int);

};

#endif // BUYWINDOW_H
